package com.neusoft.neuiotms.dcom.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.neusoft.bizcore.web.jpa.model.AbstractModel;
import com.neusoft.bizcore.web.jpa.model.Comment;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@org.hibernate.annotations.Table(appliesTo = "neuiot_scheduling_rule", comment = "排班规则表")
@Table(name = "neuiot_scheduling_rule")
public class SchedulingRule extends AbstractModel {

    private static final long serialVersionUID = 1L;

    /** 规则名称 */
    @NotBlank(message = "规则名称不能为空")
    @Length(max = 255, message = "规则名称不能超过{max}位")
    @Column(length = 255, nullable = false)
    @Comment("varchar(255) NOT NULL COMMENT '规则名称'")
    private String name;

    /** 周期数 */
    @NotNull(message = "小组数不能为空")
    @Comment("int(11) NULL COMMENT '小组数'")
    private int cycleNumber;

    /** 小组数 */
    @NotNull(message = "周期数不能为空")
    @Comment("int(11) NULL COMMENT '周期数'")
    private int groupNumber;

    /** 是否包含节假日 */
    @Column(nullable = false)
    @Comment("bit(1) NOT NULL COMMENT '是否为管理者'")
    private Boolean isIncludedHoliday = false;

    /** 关联班次 */
    @ManyToOne
    private Classes classes;

    /** 关联规则项 */
    @OneToMany(mappedBy = "rule", cascade = {CascadeType.ALL })
    @LazyCollection(LazyCollectionOption.FALSE)
    private List<SchedulingRuleItem> items = new ArrayList<>();
}
